package com.labofjet.service;

import javax.persistence.EntityManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.labofjet.entity.Student;
import com.labofjet.repository.module2.StudentRepository;

@Service
public class TestTransactionService1 {
    @Autowired
    TestTransactionService2 service;
    
    @Autowired
    private StudentRepository studentRepository;
    
    @Autowired
    private EntityManager em;

    @Transactional(propagation = Propagation.REQUIRED)
    public void operate1() {
        Student s = new Student();
        s.setId(841);
        s.setName("841o1");
        studentRepository.save(s);
        service.operate2();
        Student s3 = new Student();
        s.setId(843);
        s.setName("843o1");
        studentRepository.save(s);
    }
    
    @Transactional(propagation = Propagation.REQUIRED)
    public void operate3() {       
        Student s = new Student();
        studentRepository.save(s);
        em.flush();
        //em.clear();
        s.setName("844844jet");
    }

}
